import os
import sys
import json
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
sys.path.append(BASE_DIR)

from mail import Mailer
from settings import PlateInfo


class AllStastics(object):
    """ 统计各个纬度信息 """
    def __init__(self, test_flag=False):
        self.plate_dict = PlateInfo  # {'四库平台': {'db_name': 'siku', 'model': 'SikuStatistics'}}
        self.all_statis = {}
        self.test_flag = test_flag

    def send_mail(self, text=None, file_list=None):
        """ 发送邮件的方法 """
        # file_list   #发送文件的时候添加此参数 格式如:  [os.path.join(BASE_PATH,'file.xlsx'),]
        MAILS = {
            'host': 'smtp.163.com',
            'user': 'jianshequan@163.com',
            'password': 'MIJZPARSPBWWQAKE',
            'subject': '招投标采集更新统计',
        }
        if self.test_flag:
            MAILS['recipients'] = ['1059044764@qq.com'] # 收件人
        else:
            MAILS['recipients'] = [
                    # 'jianshequan@163.com', 'mywpython@163.com',
                    # '951016703@qq.com',  # 李洋
                    '1059044764@qq.com',  # 顾旭龙
                    ] # 收件人

        mail_obj = Mailer(**MAILS)
        if not text:
            text = '<font color="red"><strong>统计内容为空</strong></font>'  # 文章正文内容
        file_xpath = r'E:\local_tender_peoject\tender_project\Excel_Workbook.xls'
        file_list = [file_xpath]
        mail_obj.send(text, file_list=file_list)

    def run(self):
        """
        文本形式
        """
        mesg_str='<h3>==============================</h3>'
        self.send_mail(mesg_str)

def process():
    all_obj = AllStastics(True)
    # all_obj.test_run('ShuiLiStatis')
    all_obj.run()

if __name__ == '__main__':
    process()
